package com.test.daily.leetcode.y2021.m11.day1110;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2021/11/10 上午 09:00
 * @version: 1.0
 */
public class Code01_FindPoisonedDuration {
    public static void main(String[] args) {
        int[] timeSeries = new int[]{1,4};
        int duration = 2;
        Code01_FindPoisonedDuration cf = new Code01_FindPoisonedDuration();
        System.out.println(cf.findPoisonedDuration(timeSeries, duration));
    }
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int timeLine = 0;
        int ans = 0;
        for(int i = 0; i < timeSeries.length; i++){
            if(timeLine <= timeSeries[i]){
                ans += duration;
            }else{
                ans += duration + timeSeries[i] - timeLine;
            }
            timeLine = timeSeries[i] + duration;
        }
        return ans;
    }
}
